package cn.terminus.biz.customer.customleaseinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.customleaseinfo.dto.*;
import cn.terminus.data.customer.customleaseinfo.dao.CustomLeaseInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomLeaseInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:56
 */
@Component
public class CustomLeaseInfoManager extends AbstractTerminusManager {
    @Autowired
    private CustomLeaseInfoDao customLeaseInfoDao;

    public Integer add(CustomLeaseInfoNewDto dto) throws DataAccessException {
        try {
            return customLeaseInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomLeaseInfoNewDto dto) throws DataAccessException {
        try {
            return customLeaseInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomLeaseInfoResultDto> gets(CustomLeaseInfoGetsDto dto) throws DataAccessException {
        try {
            return customLeaseInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomLeaseInfoResultDto> query(CustomLeaseInfoQueryDto dto) throws DataAccessException {
        try {
            return customLeaseInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomLeaseInfoDeleteDto dto) throws DataAccessException {
        try {
            return customLeaseInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomLeaseInfoResultDto> page(CustomLeaseInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomLeaseInfoResultDto> result = (Page<CustomLeaseInfoResultDto>) customLeaseInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomLeaseInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomLeaseInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
